#!/bin/bash
# vim: fdm=marker fmr=[[[,]]] cms=\ #%s

[[ -z $SOAR ]] && SOAR=/opt/soar
PATH=$PATH:$SOAR/common/bash/soar
. soar.sh

main()
{ #[[[
    if [[ -z $SVCENV_DIR ]]
    then
        echo "Error: SVCENV_DIR not set"
        exit 1
    fi
    if [[ -z $SVCENV_CNFG ]]
    then
        echo "Error: SVCENV_CNFG not set"
        return 1
    fi
    local bin=seagent

    local running

    running=$(process_is_running $bin)
    if (( running ))
    then
        echo "$bin is still running... skip"
        return 0
    fi

    cd $SVCENV_DIR/sys/agent
    if [[ ! -x $bin ]]
    then
        echo "Error: $bin not in \$SVCENV_DIR/bin or not executable"
        return 1
    fi
    PATH=.:$PATH
    $bin
    sleep 1

    running=$(process_is_running $bin)
    if (( running ))
    then
        echo "$bin start succeed"
        return 0
    else
        echo "$bin start fail"
        return 1
    fi
} #]]]

main $@
exit $?
